<template>
  <div class="public">
    <el-card class="box-card">
      <h3 class="title">个性化缴费平台</h3>
      <!--   搜索区     -->
      <el-form :model="queryParams" ref="queryForm" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="班级" prop="deptId" style="width: 350px">
              <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true"
                          placeholder="请选择班级"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="studentName">
              <el-input
                v-model="queryParams.studentName"
                placeholder="请输入姓名"
                clearable
                style="width: 240px"
              />
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-button type="primary" style="margin-top: 20px;margin-right: 20px;margin-bottom: 20px; width: 100%;">
        学生信息列表
      </el-button>
      <el-table v-loading="loading" :data="studentsList">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="学号" align="center" prop="stuNo"/>
        <el-table-column label="姓名" align="center" prop="studentName"/>
        <el-table-column label="学校" align="center" prop="school"/>
        <el-table-column label="学院" align="center" prop="college"/>
        <el-table-column label="专业" align="center" prop="major"/>
        <el-table-column label="班级" align="center" prop="clazz"/>
        <el-table-column label="手机号码" align="center" prop="phonenumber"/>
        <el-table-column label="用户性别" align="center" prop="sex">
          <template slot-scope="scope">{{ scope.row.sex == 1 ? '女' : '男' }}</template>
        </el-table-column>
      </el-table>
    </el-card>


    <!--  底部  -->
    <div class="el-public-footer">
      <a href="https://beian.miit.gov.cn" target="_blank"><span>滇ICP备20001515号</span></a>
    </div>
  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import {queryStudent} from "@/api/campus/students";
import {schoolTree} from "@/api/campus/Org";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Public",
  components: {Treeselect},
  data() {
    return {
      // 遮罩层
      loading: false,
      // 部门树选项
      deptOptions: [],
      // 学生表格数据
      studentsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentId: null,
        studentName: null,
        userName: undefined,
        phonenumber: undefined,
        deptId: undefined,
        sex: null,
        status: 0,
      },
      // 表单参数
      form: {},
      rules: {
        deptId: [
          {required: true, message: "请输入选择班级", trigger: "blur"}
        ],
        studentName: [
          {required: true, message: "请输入姓名", trigger: "blur"}
        ],
      },
    };
  },
  created() {
    this.getDeptTree();
  },
  methods: {
    /** 查询学生列表 */
    getList() {
      this.$refs["queryForm"].validate(valid => {
        if (valid) {
          this.loading = true;
          queryStudent(this.queryParams).then(response => {
            this.studentsList = response.data;
            this.loading = false;
          });
        }
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      schoolTree().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">

.public {
  margin: 20px;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.el-public-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
</style>
